<?
/**
 * 广告位置分类
 *
 */
class Fittings extends MyBase{
	private $categorys = array();
	
	function __construct() {
		parent::__construct('fittings.id', array('keyword' => 'name'));
	}
	
	/**
	 * 修改配件
	 */
	public function edit($post){
		$id = empty($post['id']) ? 0 : intval($post['id']);
		$select = array('name' => $post['name'], 'isdel' => 0);
		if($id > 0){
			$select['kept'] = " AND `id`!={$id}";
		}
		$rs = $this->db->get_row($this->tbname, $select, 'id');
		if(!empty($rs)){
			return $this->rwarn(lang('already') . lang('exist'));
		}
		
		$data = array(
			'name'		=> $post['name'],
			'rank'		=> $post['rank'],
			'memo'		=> $post['memo'],
		);
		if($id > 0){
			$data['updatetime'] = TIME;
			$r = $this->db->update($this->tbname, array('id' => $id), $data);
		}else{
			$data['addtime'] = TIME;
			$r = $id = $this->db->insert($this->tbname, $data);
		}
		return $r;
	}
}
?>